package org.eclipseuseradmin.ui.editors;

import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.forms.SectionPart;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.forms.widgets.TableWrapData;
import org.eclipse.ui.forms.widgets.TableWrapLayout;
import org.eclipseuseradmin.internal.ui.editors.EditorsMessages;
import org.eclipseuseradmin.ui.model.RoleElementModel;

public class RoleElementGeneralInfoSection extends SectionPart {

	protected RoleElementOverviewPage page;

	protected Composite client;

	protected Label nameLabel;

	protected Label nameText;

	public RoleElementGeneralInfoSection(Composite parent,
			RoleElementOverviewPage page, int style) {

		this(
				parent,
				page,
				EditorsMessages.get().RoleElementGeneralInfoSection_title,
				EditorsMessages.get().RoleElementGeneralInfoSection_description,
				EditorsMessages.get().RoleElementGeneralInfoSection_tooltip,
				style);
	}

	public RoleElementGeneralInfoSection(Composite parent,
			RoleElementOverviewPage page, String title, String description,
			String tooltip, int style) {

		super(parent, page.getEditor().getToolkit(), style);
		this.page = page;
		Section section = getSection();
		section.setText(title);
		section.setDescription(description);
		section.setToolTipText(tooltip);
		createClient(getSection(), page.getEditor().getToolkit());
	}

	protected DataBindingContext getBindingContext() {
		return page.getBindingContext();
	}

	protected RoleElementOverviewPage getRoleElementPage() {
		return page;
	}

	protected RoleElementModel getModel() {
		return page.getRoleElementEditor().getModel();
	}

	protected void createClient(Section section, FormToolkit toolkit) {

		client = toolkit.createComposite(section);
		TableWrapLayout layout = new TableWrapLayout();
		layout.numColumns = 2;
		client.setLayout(layout);
		section.setClient(client);

		nameLabel = toolkit.createLabel(client,
				EditorsMessages.get().RoleElementGeneralInfoSection_name);
		nameText = toolkit.createLabel(client, getModel().getName());
		TableWrapData layoutData = new TableWrapData(TableWrapData.FILL_GRAB);
		nameText.setLayoutData(layoutData);
	}

}
